package it.okkam.utility;

import it.okkam.strutturedati.Poligono;
import it.okkam.strutturedati.Punto;
import it.okkam.strutturedati.Vertice;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;


public class ExtentParticelle {

public Double[] getExtentMin(Poligono poligono) {
		
		Double[] extentMin= new Double[2];
		List<Double> lat = new ArrayList<Double>();
		List<Double> lon = new ArrayList<Double>();
		
		lat = getLatArray(poligono);
		lon = getLonArray(poligono);
		
		extentMin[0] = getLatMin(lat);
		extentMin[1] = getLonMin(lon);
			
		return extentMin;
	}

public Double[] getExtentMax(Poligono poligono) {
	
	Double[] extentMax= new Double[2];
	List<Double> lat = new ArrayList<Double>();
	List<Double> lon = new ArrayList<Double>();
	
	lat = getLatArray(poligono);
	lon = getLonArray(poligono);
	
	extentMax[0] = getLatMax(lat);
	extentMax[1] = getLonMax(lon);
		
	return extentMax;
}
	
	public List<Double> getLatArray (Poligono poligono) {
		List<Double> lat = new ArrayList<Double>();
		Set<Vertice> listaVertici = new HashSet<Vertice>();
		listaVertici = poligono.getPoligono();
		Iterator<Vertice> it = listaVertici.iterator();
		while (it.hasNext()){
			Vertice vertex = it.next();
			Punto point = vertex.getVertice();
			double latitudine = point.getX();
			lat.add(latitudine);			
		}
		return lat;
	}
	
	public List<Double> getLonArray (Poligono poligono) {
		List<Double> lon = new ArrayList<Double>();
		Set<Vertice> listaVertici = new HashSet<Vertice>();
		listaVertici = poligono.getPoligono();
		Iterator<Vertice> it = listaVertici.iterator();
		while (it.hasNext()){
			Vertice vertex = it.next();
			Punto point = vertex.getVertice();
			double longituidine = point.getY();
			lon.add(longituidine);			
		}
		return lon;
	}
	
	public double getLatMin (List<Double> listaIn) {
		return Collections.min(listaIn);
	}
	
	public double getLatMax (List<Double> listaIn) {
		return Collections.max(listaIn);
	}
	
	public double getLonMin (List<Double> listaIn) {
		return Collections.min(listaIn);
	}
	
	public double getLonMax (List<Double> listaIn) {
		return Collections.max(listaIn);
	}
}
